function createjsDOMenu(customReports){

	// Exclusion list menu.
	var exclusionsListMenu = new jsDOMenu(170);
	with(exclusionsListMenu){
		addMenuItem(new menuItem("Add to List", "", "code:addToMailingListExclusionList()"));
		addMenuItem(new menuItem("Export List", "", "code:exportMailingListExclusionList()"));
		//addMenuItem(new menuItem("Import List", "", "code:"));
		addMenuItem(new menuItem("Retrieve List", "", "code:retrieveMailingListExclusionList()"));
		addMenuItem(new menuItem("-"));
		addMenuItem(new menuItem("Delete List", "", "code:deleteMailingListExclusionList()"));
	}
	
	// Custom Reports Menu.
	var customReportsMenu = new jsDOMenu(170);
	with(customReportsMenu){
		addMenuItem(new menuItem("Create Custom Report","","code:createCustomReportFromTab1Companies()"));
		addMenuItem(new menuItem("-"));
	}

	if(customReports != null){
		// if there are too many custom reports for this user, then group them into 
		// multiple sub-menus under the custom reports menu. Else, show them directly.
		if(customReports.length <= 10){
			createSimpleCustomReportsMenus(customReports, customReportsMenu);
		}else{
			createMultiLevelSimpleCustomReportsMenus(customReports, customReportsMenu);
		}
	}
	
	var menuBar = new jsDOMenuBar("static", "staticMenuBar", "", "",300); //CREATE MAIN MENU ITEMS
	with (menuBar) {
		addMenuBarItem(new menuBarItem(":: mailing list exclusions", exclusionsListMenu));
		addMenuBarItem(new menuBarItem(":: custom reports", customReportsMenu));
		addMenuBarItem(new menuBarItem(":: log out",null,"",true,"code:logOut(document.frm);"));
	}
	
}

// function used to create the custom reports menu when there are a limited number of custom reports.
function createSimpleCustomReportsMenus(customReports, customReportsMenu){
	for(var i=0;i<customReports.length;i++){
		with (customReportsMenu) {
			addMenuItem(new menuItem(customReports[i].reportTitle, "item" + i));
		}

		var settingsSubMenu = createDownloadRenameDeleteSubMenus(customReports[i]);
		
		customReportsMenu.items["item" + i].setSubMenu(settingsSubMenu); //ASSOCIATE SUB MENU WITH PARENT MENU ITEM
	}
}

// function to create multi-level menus, grouping reports into multiple sub-menus to prevent
// UI issues when the number of custom reports are large.
function createMultiLevelSimpleCustomReportsMenus(customReports, customReportsMenu){
	for(var i=0;i<customReports.length;i+=10){
		with (customReportsMenu) {
			addMenuItem(new menuItem("Reports " + (i + 1) + " to " + (i + 10), "Group" + i));
			
			var reportsMenu = new jsDOMenu(150);
			for(var j=i; j < (i+10);j++){
				if(j < customReports.length){
					with(reportsMenu){
						addMenuItem(new menuItem(customReports[j].reportTitle, "item" + j));
						var settingsSubMenu = createDownloadRenameDeleteSubMenus(customReports[j]);
						items["item" + j].setSubMenu(settingsSubMenu); 
					}
				}
			}
			items["Group" + i].setSubMenu(reportsMenu); 
		}		
	}
}

function createDownloadRenameDeleteSubMenus(customReport){
	var settingsSubMenu = new jsDOMenu(150);
	with (settingsSubMenu) {
		addMenuItem(new menuItem("Download", "", "code:downloadCustomReport(" + customReport.reportTitlesId + ",'" + customReport.reportTitle.replace("'", "\\'") + "')"));
		addMenuItem(new menuItem("Rename", "", "code:renameCustomReport(" + customReport.reportTitlesId + ",'" + customReport.reportTitle.replace("'", "\\'")  + "')"));
		addMenuItem(new menuItem("Delete", "", "code:deleteCustomReport(" + customReport.reportTitlesId + ",'" + customReport.reportTitle.replace("'", "\\'")  + "')"));
		
	}
	
	return settingsSubMenu;
}